// ignore_for_file: must_be_immutable

/*
 * @Author: CodeHare
 * @Date: 2023-10-09 09:39:35
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-21 15:10:56
 * @Description: 能量柱状图表
 */
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_echarts/flutter_echarts.dart';
import 'package:get/get.dart';
import 'package:yt_devops/resources/str_res_keys.dart';

import '../../../../../../components/log_utils.dart';

class ChargeStationTrendsChart extends StatelessWidget {
  final List<dynamic> chargingOrderCount;
  final List<dynamic> chargingTimes;
  final List<dynamic> chargingCapacityList;
  final List<dynamic> chargingFee;
  final List<dynamic>? timeList;
  // final num powerMaxValue;
  // final num powerMinValue;
  const ChargeStationTrendsChart(
      {super.key,
      required this.chargingOrderCount,
      required this.chargingTimes,
      required this.chargingCapacityList,
      required this.chargingFee,
      required this.timeList,
      // required this.powerMaxValue,
      // required this.powerMinValue
      });

  @override
  Widget build(BuildContext context) {
    Log.d('ChargeStationTrendsChart===');
    return Echarts(
      captureHorizontalGestures: true,
      option: '''
      {
  /// 提示框
  tooltip: {
    trigger: 'axis',
    backgroundColor: 'rgba(0,0,0,0.85)',
    borderWidth: 0,
    opacity: 0.2,
    confine: true,
    padding: [
      10, // 上
      8, // 右
      10, // 下
      8 // 左
    ],
    textStyle: {
      color: 'white'
    },
    axisPointer: {
      /// 坐标轴指示器配置项
      lineStyle: {
        color: 'rgba(0,0,0,0.09)',
        position: function (pt) {
          return [pt[0], 500];
        }
      }
    },

  },
  /// 坐标轴
  grid: {
    containLabel: true,
    top: '3%',
    left: '5%',
    right: '5%',
    bottom: 42
  },
  /// 横轴
  xAxis: {
    type: 'category',
    data: ${jsonEncode(timeList)},  
          splitLine: {
        lineStyle: {
          type: 'dashed', //虚线
        },
      },             
    axisLine:{
      show: false,
    }, 
    axisTick: {
      show: false
    }, 
    axisLabel: {
      color: '#999999',
      fontSize: 11,
      lineStyle: {
          type: 'dashed', //虚线
        },
      interval: function (index) { // 自定义间隔函数 
          if (index % 4 === 0) { // 每四小时显示一次  // 返回值是五分钟为一个间隔
              return true;
          } else {
              return false;
          }
      },
    },
  },
  yAxis: [
    {
      name: '',
      type: 'value',
    
          max:function (value) {
             return (typeof value.max === 'number' && isNaN(value.max))?1:null;
        },
       min:function (value) {
             return (typeof value.min === 'number' && isNaN(value.min))?0:null;
        },
        // max:100,
        // min: 0,
      // offset: 4,
        splitLine: {
        lineStyle: {
          type: 'dashed', //虚线
        },
      },
      axisLabel: {
        color: '#999999',
        fontSize: 11
      },
    },
    {
      name: '',
      type: 'value',
      splitLine: {
        lineStyle: {
          type: 'dashed', //虚线
        },
      },
      // min: 0,
      // max: 25,
      // interval: 5,
      offset: 4,
      axisLabel: {
        color: '#999999',
        fontSize: 11
      },
    }
  ],
    legend: {
    show: true,
    icon: 'rect',

    bottom:5,
    left: '5%',
    right: '5%',
    itemHeight: 3,
    itemWidth: 12,
     textStyle: {
      borderRadius: [2, 2, 2, 2]
    },
    padding: [
    0,  // 上
    0, // 右
    0,  // 下
    0, // 左
]
  },
  series: [
    {
      name:  '${ResKey.deviceChargeOrderNum.tr}',// '充电订单数',
      type: 'line',
      data: ${jsonEncode(chargingOrderCount)}      
    },
    {
      name: '${ResKey.deviceChargeHourNum.tr}',//'充电时长',
      type: 'line',
       data: ${jsonEncode(chargingTimes)}  
    },
    {
      name: '${ResKey.chargingCapacity.tr}',//'充电量',
      type: 'line',
       data: ${jsonEncode(chargingCapacityList)}  
    },
     {
      name: '${ResKey.deviceChargeFee.tr}',//'充电费用',
      type: 'line',
       data: ${jsonEncode(chargingFee)}  
    },
  ]
}
      ''',
    );
  }
}
